$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        init:function () {
            this.funObj().loadWidth();
            $('#list_province,#list_city,#list_county,#stats_type').select2();
            this.listener();
        },
        listener:function () {
            var $this = this;
            //省改变
            $('#list_province').change(function () {
                $this.funObj().loadArea($(this).val(),'list_city', '全部市');
                $this.funObj().loadArea(0,'list_county', '全部区');
                $this.funObj().triggerLoad();
            });
            //市改变
            $('#list_city').change(function () {
                $this.funObj().loadArea($(this).val(),'list_county', '全部区');
                $this.funObj().triggerLoad();
            });

            //区改变
            $('#list_county').change(function () {
                $this.funObj().triggerLoad();
            });

            //统计方式
            $('#stats_type').change(function () {
                $this.funObj().triggerLoad();
            });
            // //查看学校统计
            // $('#see_schoolStats').click(function () {
            //     $this.funObj().openSchoolStats();
            // });
        },
        funObj:function () {
            var $this = this;
            return {
                loadArea:function (areaCode,seletor, placeHolder) {
                    xhExtra.ajaxRequest('ims/stats/getAreaByCode', {code:areaCode},{}, function (res) {
                        var str = '<option value="0" selected>'+placeHolder+'</option>';
                        if (res.length > 0) {
                            $.each(res,function (i,item) {
                                str +='<option value="'+item['id']+'">'+item['text']+'</option>';
                            });
                        }
                        $('#'+seletor).empty().append(str);
                    })
                },
                triggerLoad:function () {
                    window.top.xhTop.getActiveFrame()['imsFrame']['mainFrame'].obj.funObj().loadPayLine();
                },
                loadWidth:function() { //根据页面大小 变化 图标大小
                    var height = $(document.body).outerHeight(true) - 120;
                    $('[name=mainFrame]').attr('style','width: 100%;height: '+height+'px;');
                    window.onresize = function(){  //重新定义界面大小处理
                        var height = $(document.body).outerHeight(true) - 120;
                        $('[name=mainFrame]').attr('style','width: 100%;height: '+height+'px;');
                        window.top.xhTop.getActiveFrame()['mainFrame'].obj.funObj().loadPayLine();
                    };
                },
                openSchoolStats:function () {
                    window.top.xhTop.createNewTab('各校库存统计', baseUrl+'ims/stats/schoolIms');
                }
            }
        }
    }
};